﻿#ifndef PST_TABLECHATWINDOW_H
#define PST_TABLECHATWINDOW_H

#include <QWidget>
#include "Graph3DWindowBase.h"
#include "TableSettings.h"
#include "InfomationGraph3DBasical.h"

class QStandardItem;

namespace pst {

    class TableDisplayWindow;
    class TableSettings;

    class TableChatWindow : public Graph3DWindowBase
    {
        Q_OBJECT
    
    public:
        void addDataToWindow(InfomationGraph3DBasical* info);
        void setTableDataInfo();
        void setTableDataSource(QString dataSource);
        void addDataFilterVarItem();

        void setWindowID(int windowID) override;
        int getWindowID() const override;

        void setWindowUniversalID(int windowUniversalID) override;
        int getWindowUniversalID() const override;

        InfomationGraph3DBasical* getTableChartDataInfo() { return m_info; };

        /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false) override;

        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false) override;

        TableDisplayWindow* getTableWidget() { return m_tableWidget; }
        bool exportTableData(const QString& path,  const QChar& delimiter = ',', bool onlyVisible = true, bool savePy = true);

        // python
        void pyHideOrShowTableColumn(QSet<int>& selectedIndexs);
        void pyRenameColName(int colIndex, QString newName);
        void pyFlushTableBySelectedRow(QString args);
        void pyHighlightSelectedTbColumns(QString parms);

        bool saveScreenShot(const QString& path) override;

    public:
        TableChatWindow(QWidget* parent = nullptr);
        ~TableChatWindow();

    private slots:
        void slot_flushTableBySelectedRow(QHash<int, QStringList> map, bool savePy);
        //左侧关闭工程树，删除相应的图像
        // 注意items是左侧工程树的节点
        void slot_closeTree(const QList<QStandardItem*>& items);
        void clearWindow();

    private:    
        void hideOrShowTableColumn(QSet<int>& selectedIndexs, bool savePy = true);
        void changeColumnName(QHash<int, QString>& hash, bool& execRes);
        void highlightSelectedTableColumns(QSet<int>& selectedIndexs);
        bool tableColRename(QHash<int, QString>& hash);
        void flushTableBySelectedRow(QHash<int, QStringList> map, bool savePy = true);
        void highlightSelectedTbColumns(QSet<int>& selectedIndexs, bool savePy = true);




        void CompareItemInformationDataChanges(QList<TableChartWindowSidebarData::TableDataitemInformation> oriData, QList<TableChartWindowSidebarData::TableDataitemInformation> newData);
        void CompareDataChanges(QHash<int, QStringList> oriData, QHash<int, QStringList> newData);
        
    private:
        int m_windowUniversalID{-1};
        int m_tableChatWindowID{0};
        TableDisplayWindow* m_tableWidget;
        TableSettings* m_tableSettings;

        InfomationGraph3DBasical* m_info;
    };
}
#endif
